<meta charset="UTF-8"> <!-- for HTML5 -->

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<html lang="en">
<script type="text/javascript" src="http://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>
<label for="ipaddr"></label><input type="text" id="ipaddr" name="ipaddr" placeholder="ip_addr" value="192.168.243.196">
<button onclick="connect()">连接</button>
<button onclick="deconnect()">断开</button>
<br>
<label for="msg"></label><input type="text" id="msg" name="msg" placeholder="消息">
<button onclick="send_msg()">发送</button>
<br>
<button onclick="led_on()">led_on</button>
<button onclick="led_off()">led_off</button>
<br>
<button onclick="open_door()">open_door</button>
<button onclick="close_door()">close_door</button>
<br>
<button onclick="open_win()">open_win</button>
<button onclick="close_win()">close_win</button>
<br>
<button onclick="leave()">leave</button>
<button onclick="auto()">auto</button>

</html>
<script>
    function connect() {
        $.ajax({
            url: "connect",
            type: "POST",
            data: {"ipaddr": $("#ipaddr").val()},
            success: function (result) {
                alert(result.message)
            }
        });
    }

    function deconnect() {
        $.ajax({
            url: "deconnect",
            type: "POST",
            data: {"ipaddr": $("#ipaddr").val()},
            success: function (result) {
                alert(result.message)
            }
        });
    }

    function send_msg() {
        $.ajax({
            url: "send_msg",
            type: "POST",
            data: {"msg": $("#msg").val()},
            success: function (result) {
                console.log(result.message)
            }
        });
    }

    function led_on() {
        $.ajax({
            url: "led_on",
            type: "POST",
            data: {"data": "led on"},
            success: function (result) {
                console.log(result.message)
            }
        });
    }

    function led_off() {
        $.ajax({
            url: "led_off",
            type: "POST",
            data: {"data": "led off"},
            success: function (result) {
                console.log(result.message)
            }
        });
    }
        function open_door() {
        $.ajax({
            url: "open_door",
            type: "POST",
            data: {"data": "open door"},
            success: function (result) {
                console.log(result.message)
            }
        });
    }
          function close_door() {
        $.ajax({
            url: "close_door",
            type: "POST",
            data: {"data": "close door"},
            success: function (result) {
                console.log(result.message)
            }
        });
    }
            function open_win() {
        $.ajax({
            url: "open_win",
            type: "POST",
            data: {"data": "open window"},
            success: function (result) {
                console.log(result.message)
            }
        });
    }
          function close_win() {
        $.ajax({
            url: "close_door",
            type: "POST",
            data: {"data": "close window"},
            success: function (result) {
                console.log(result.message)
            }
        });
    }
  function leave() {
        $.ajax({
            url: "leave",
            type: "POST",
            data: {"data": "leave"},
            success: function (result) {
                console.log(result.message)
            }
        });
    }

    function auto() {
        $.ajax({
            url: "auto",
            type: "POST",
            data: {"data": "auto"},
            success: function (result) {
                console.log(result.message)
            }
        });
    }
{#    #}
    function send_off1() {
        $.ajax({
            url: "led_off",
            type: "POST",
            data: {"data": "OFF"},
            success: function (result) {
                console.log(result.message)
            }
        });
    }
{#    #}
</script>
